import request from '@/config/axios'

/**
 * 分账类型
 * INVITE 邀请奖励分账
 * SALE 签单奖励分账
 * AGENCY 代理佣金分账
 * PERSUP 个人供应商分账
 * ENTSUP 企业供应商分账
 */
export type CheckoutType = 'INVITE' | 'SALE' | 'AGENCY' | 'PERSUP' | 'ENTSUP'

/**
 * 分账通道
 * WXFZ 微信分账
 * TAX 税筹发放
 * OFFLINE 线下发放
 */
export type CheckoutPath = 'WXFZ' | 'TAX' | 'OFFLINE'

/** 结算状态：1 未结算 2 已结算 */
export enum CheckoutStatus {
  UNCHECKOUT = 1,
  CHECKOUT = 2
}

export type CheckoutOrderVO = {
  id: string
  member: {
    nickname: string
    avatar: string
  }
  trainOrderId: string
  checkoutType: CheckoutType
  checkoutPath: CheckoutPath
  checkoutAccount: string
  checkoutAmount: number
  checkoutDelay: number
  status: CheckoutStatus
  createTime: number
  updateTime: number
}

export type CheckoutOrderQuery = {
  trainOrderNo?: string
  checkoutType?: CheckoutType
  checkoutStatus?: CheckoutStatus
}

export type CheckoutOrderDTO = Partial<CheckoutOrderVO>

const baseURL = '/train/checkout-order'

export const getPage = async (params: PageParam & CheckoutOrderQuery) => {
  return await request.post<PageResult<CheckoutOrderVO>>({ url: `${baseURL}/page`, data: params })
}

/** 根据id更新结算单状态（手动结算 */
export const updateStatusById = async (checkoutOrderId: string, status: number) => {
  return await request.post({ url: `${baseURL}/update-status`, data: { checkoutOrderId, status } })
}

export const deleteById = async (id: string) => {
  return await request.delete({ url: `${baseURL}/delete-by-id`, params: { id } })
}
